﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class D04_Mathf2 : MonoBehaviour
{
    private void Start1()
    {
        Mathf.Clamp(5, 10, 20);//把5限制在10-20之间      输出10
    }

    //限制Z轴只能0-10
    private void Update()
    {
        transform.Translate(Vector3.forward * Time.deltaTime * 20f * Input.GetAxisRaw("Vertical"));

        //限制
        //拿到当前位置
        Vector3 pos = transform.position;
        pos.z = Mathf.Clamp(pos.z, 0, 10);//限制z轴位置
        transform.position = pos;
    }
}